package com.hcy.performancepro.service.performanceTool.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuled.test.tool_config.DisableUtil;
import com.hcy.performancepro.bo.performanceTool.RecordServiceBo;
import com.hcy.performancepro.dao.performanceTool.PerformanceToolServiceDao;
import com.hcy.performancepro.po.performanceTool.RecordController;
import com.hcy.performancepro.po.performanceTool.RecordService;
import com.hcy.performancepro.service.performanceTool.PerformanceToolServiceService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("performanceToolServiceServiceImpl")
@DisableUtil
public class PerformanceToolServiceServiceImpl extends ServiceImpl<PerformanceToolServiceDao, RecordService> implements PerformanceToolServiceService {

    public Wrapper<RecordService> getWrapper(RecordServiceBo recordServiceBo){
        LambdaQueryWrapper<RecordService> wrapper = Wrappers.lambdaQuery();
        wrapper.like(StrUtil.isNotBlank(recordServiceBo.getLevel()), RecordService::getLevel, recordServiceBo.getLevel());
        wrapper.like(StrUtil.isNotBlank(recordServiceBo.getRequestId()), RecordService::getRequestId, recordServiceBo.getRequestId());
        wrapper.like(StrUtil.isNotBlank(recordServiceBo.getFunctionName()), RecordService::getFunctionName, recordServiceBo.getFunctionName());
        wrapper.like(StrUtil.isNotBlank(recordServiceBo.getModuleName()), RecordService::getModuleName, recordServiceBo.getModuleName());
        wrapper.like(StrUtil.isNotBlank(recordServiceBo.getCostTime()), RecordService::getCostTime, recordServiceBo.getCostTime());
        wrapper.like(StrUtil.isNotBlank(recordServiceBo.getTimestamp()), RecordService::getTimestamp, recordServiceBo.getTimestamp());
        wrapper.like(StrUtil.isNotBlank(recordServiceBo.getParams()), RecordService::getParams, recordServiceBo.getParams());
        wrapper.like(StrUtil.isNotBlank(recordServiceBo.getReturnMessage()), RecordService::getReturnMessage, recordServiceBo.getReturnMessage());
        wrapper.like(StrUtil.isNotBlank(recordServiceBo.getExceptionMessage()), RecordService::getExceptionMessage, recordServiceBo.getExceptionMessage());
        return wrapper;
    }

    @Override
    public List<RecordService> sarchlist(Integer currentPage, Integer pageSize, RecordServiceBo recordServiceBo) {
        return baseMapper.selectList(new Page<>(currentPage, pageSize), getWrapper(recordServiceBo));
    }

    @Override
    public Long countNumber(RecordServiceBo recordServiceBo) {
        return baseMapper.selectCount(getWrapper(recordServiceBo));
    }
}
